//index.js
//获取应用实例
const app = getApp()
var a = -1;
var b = -1;
var c = -1;
var d = -1;
Page({ 
  data: {
    num: 6,
    states: 6,
    // 认证参数
    showIden: false,
    // 充值参数
    showVIP: false,
    // 老用户登陆参数
    showUser: false,
    // 输入框文字变化
    placeholder: "分销找房难，找猫眼看房",
    showsearch: false,
    // 省份名字
    province: "海南",
    // 省份显示隐藏判断参数
    showModal: false,
    showChoose: false,
    // 选择省份参数
    sts: 0,
    // 筛选条件
    area: '区域',
    myprice: '价格',
    myhouse: '几房',
    more: '更多',
    // 筛选城市
    itemList: [{
        id: 1,
        name: '市区',
        isSelected: false,
      },
      {
        id: 2,
        name: '三亚湾',
        isSelected: false,
      },
      {
        id: 3,
        name: '海棠湾',
        isSelected: false,
      },
      {
        id: 4,
        name: '红塘湾',
        isSelected: false,
      },
      {
        id: 5,
        name: '亚龙湾',
        isSelected: false,
      },
      {
        id: 6,
        name: '海棠湾',
        isSelected: false,
      },
      {
        id: 4,
        name: '红塘湾',
        isSelected: false,
      },
      {
        id: 5,
        name: '亚龙湾',
        isSelected: false,
      },
      {
        id: 6,
        name: '海棠湾',
        isSelected: false,
      },
    ],
    // 筛选价格
    pricetype: 0,
    totalList: [{
        id: 0,
        price: '不限',
        selectImage: false,
      },
      {
        id: 1,
        price: '100万以下',
        selectImage: false,
      },
      {
        id: 2,
        price: '100-200万',
        selectImage: false,
      },
      {
        id: 3,
        price: '200-300万',
        selectImage: false,
      },
      {
        id: 4,
        price: '300-500万',
        selectImage: false,
      },
      {
        id: 5,
        price: '500-1000万',
        selectImage: false,
      },
      {
        id: 6,
        price: '1000万以上',
        selectImage: false,
      },
      {
        id: 4,
        price: '300-500万',
        selectImage: false,
      },
      {
        id: 5,
        price: '500-1000万',
        selectImage: false,
      },
      {
        id: 6,
        price: '1000万以上',
        selectImage: false,
      },
    ],
    avgList: [{
        id: 0,
        price: '不限',
        selectImage: false,
      },
      {
        id: 1,
        price: '5000元/平方米以下',
        selectImage: false,
      },
      {
        id: 2,
        price: '5000-8000元/平方米',
        selectImage: false,
      },
      {
        id: 3,
        price: '8000-12000元/平方米',
        selectImage: false,
      },
      {
        id: 4,
        price: '12000-15000元/平方米',
        selectImage: false,
      },
      {
        id: 5,
        price: '15000-20000元/平方米',
        selectImage: false,
      },
      {
        id: 6,
        price: '20000元/平方米以上',
        selectImage: false,
      },
    ],
    // 筛选几房
    typeList: [{
        id: 0,
        name: '一房',
        selectImage: false,
      },
      {
        id: 1,
        name: '两房',
        selectImage: false,
      },
      {
        id: 2,
        name: '三房',
        selectImage: false,
      },
      {
        id: 3,
        name: '四房',
        selectImage: false,
      },
      {
        id: 4,
        name: '五房以上',
        selectImage: false,
      },
    ],
    // 更多
    moreList: [{
      title: "物业类型",
      property: [{
          id: 0,
          name: '高层住宅',
          selectImage: false,
        },
        {
          id: 1,
          name: '别墅',
          selectImage: false,
        },
        {
          id: 2,
          name: '洋房',
          selectImage: false,
        },
        {
          id: 3,
          name: '酒店式公寓',
          selectImage: false,
        },
        {
          id: 4,
          name: '写字楼',
          selectImage: false,
        },
        {
          id: 5,
          name: '商铺',
          selectImage: false,
        },
      ],
    }, {
      title: "装修",
      property: [{
          id: 0,
          name: '毛坯',
          selectImage: false,
        },
        {
          id: 1,
          name: '精装修',
          selectImage: false,
        },
        {
          id: 2,
          name: '拎包入住',
          selectImage: false,
        },
      ],
    }, {
      title: "产权",
      property: [{
          id: 0,
          name: '70年住宅',
          selectImage: false,
        },
        {
          id: 1,
          name: '50年商业',
          selectImage: false,
        },
        {
          id: 2,
          name: '40年商业',
          selectImage: false,
        },
      ],
    }, {
      title: "户型状态",
      property: [{
          id: 0,
          name: '在售',
          selectImage: false,
        },
        {
          id: 1,
          name: '认筹',
          selectImage: false,
        },
        {
          id: 2,
          name: '待售',
          selectImage: false,
        },
        {
          id: 3,
          name: '二手',
          selectImage: false,
        },
      ],
    }, {
      title: "楼盘状态",
      property: [{
          id: 0,
          name: '未开盘',
          selectImage: false,
        }, 
        {
          id: 1,
          name: '待开盘',
          selectImage: false,
        },
        {
          id: 2,
          name: '即将开盘',
          selectImage: false,
        },
        {
          id: 3,
          name: '认筹',
          selectImage: false,
        },
        {
          id: 4,
          name: '在售',
          selectImage: false,
        },
        {
          id: 5,
          name: '待售',
          selectImage: false,
        },
        {
          id: 6,
          name: '封盘',
          selectImage: false,
        },
        {
          id: 7,
          name: '不签分销',
          selectImage: false,
        },
      ],
    }, {
      title: "特别关注",
      property: [{
          id: 0,
          name: '带温泉',
          selectImage: false,
        },
        {
          id: 1,
          name: '海景',
          selectImage: false,
        },
        {
          id: 2,
          name: '可指定带看',
          selectImage: false,
        },
        {
          id: 3,
          name: '可垫资结佣',
          selectImage: false,
        },
        {
          id: 4,
          name: '海景',
          selectImage: false,
        },
        {
          id: 5,
          name: '现房',
          selectImage: false,
        },
      ],
    }, {
      title: "面积",
      property: [{
          id: 0,
          name: '60以下',
          selectImage: false,
        },
        {
          id: 1,
          name: '60-80',
          selectImage: false,
        },
        {
          id: 2,
          name: '80-100',
          selectImage: false,
        },
        {
          id: 3,
          name: '100-120',
          selectImage: false,
        },
        {
          id: 4,
          name: '120-150',
          selectImage: false,
        },
        {
          id: 5,
          name: '150-200',
          selectImage: false,
        },
        {
          id: 6,
          name: '200以上',
          selectImage: false,
        },
      ],
    }, ],
  },
  onLoad: function() {

  },
  // 输入搜索文字时隐藏方法
  searchword: function(e) {
    this.setData({
      placeholder: "",
      showsearch: true
    });
  },
  // 移除焦点
  moveword: function(e) {
    var val = e.detail.value;
    if (val == '') {
      this.setData({
        placeholder: "分销找房难，找猫眼看房",
        showsearch: false
      });
    }
  },
  // 显示省份方法
  getProvince: function() {
    this.data.showModal = !this.data.showModal;
    this.setData({
      showModal: this.data.showModal
    });
    this.isShow();
  },
  // 选择省份法方法
  getChoose: function(e) {
    var sts = e.currentTarget.dataset.sts;
    var name = e.currentTarget.dataset.name;
    var that = this;
    that.setData({
      sts: sts,
      province: name
    });
    setTimeout(function() {
      that.setData({
        showModal: false
      });
    }, 800)
  },
  // 判断是否显示蒙层以及筛选条件
  isShow: function() {
    var that = this;
    var num = that.data.num;
    var states = that.data.states;
    var showChoose = that.data.showChoose;
    if (num == 0) {
      states = 0;
      showChoose = true;
      a += 1;
      b = -1;
      c = -1;
      d = -1;
      if (a % 2 == 1) {
        states = 6;
        num = 6;
        showChoose = false;
      }
    } else if (num == 1) {
      states = 1;
      showChoose = true;
      a = -1;
      b += 1;
      c = -1;
      d = -1;
      if (b % 2 == 1) {
        states = 6;
        num = 6;
        showChoose = false;
      }
    } else if (num == 2) {
      states = 2;
      showChoose = true;
      a = -1;
      b = -1;
      c += 1;
      d = -1;
      if (c % 2 == 1) {
        states = 6;
        num = 6;
        showChoose = false;
      }
    } else if (num == 3) {
      states = 3;
      showChoose = true;
      a = -1;
      b = -1;
      c = -1;
      d += 1;
      if (d % 2 == 1) {
        states = 6;
        num = 6;
        showChoose = false;
      }
    }
    this.setData({
      states: states,
      num: num,
      showChoose: showChoose
    })
  },
  // 筛选下拉显示隐藏
  changeBoxBtn: function(e) {
    var num = e.currentTarget.dataset.num;
    var states = null;
    var showChoose = '';
    if (num == 0) {
      states = 0;
      showChoose = true;
      a += 1;
      b = -1;
      c = -1;
      d = -1;
      if (a % 2 == 1) {
        states = 6;
        num = 6;
        showChoose = false;
      }
    } else if (num == 1) {
      states = 1;
      showChoose = true;
      a = -1;
      b += 1;
      c = -1;
      d = -1;
      if (b % 2 == 1) {
        states = 6;
        num = 6;
        showChoose = false;
      }
    } else if (num == 2) {
      states = 2;
      showChoose = true;
      a = -1;
      b = -1;
      c += 1;
      d = -1;
      if (c % 2 == 1) {
        states = 6;
        num = 6;
        showChoose = false;
      }
    } else if (num == 3) {
      states = 3;
      showChoose = true;
      a = -1;
      b = -1;
      c = -1;
      d += 1;
      if (d % 2 == 1) {
        states = 6;
        num = 6;
        showChoose = false;
      }
    }
    this.setData({
      states: states,
      num: num,
      showChoose: showChoose
    })
  },
  // 筛选城市
  clickCity: function(e) {
    var city = e.currentTarget.dataset.index;
    this.setData({
      city: city
    })
  },
  //筛选市区
  clickLimt: function(e) {
    var town = e.currentTarget.dataset.index;
    var that = this;
    for (let i in that.data.itemList) {
      var item = that.data.itemList[i];
      item.isSelected = false;
      that.setData({
        town: town,
        itemList: that.data.itemList,
      });
    }
  },
  clickTown: function(e) {
    var index = e.currentTarget.dataset.index - 1;
    var that = this;
    var item = that.data.itemList[index];
    item.isSelected = !item.isSelected;
    that.setData({
      town: 999,
      itemList: that.data.itemList,
    });
  },
  // 重置城市
  areaReset: function() {
    this.setData({
      city: '999'
    });
    var that = this;
    for (let i in that.data.itemList) {
      var item = that.data.itemList[i];
      item.isSelected = false;
      that.setData({
        town: 999,
        itemList: that.data.itemList,
      });
    }
  },
  // 确定城市市区筛选
  areaSure: function() {
    var that = this;
    setTimeout(function() {
      that.isShow();
    }, 800)
  },
  // 价格筛选
  clickPrice: function(e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      pricetype: index
    })
  },
  totalPrice: function(e) {
    var idx = e.currentTarget.dataset.index;
    var that = this;
    var pricetype = that.data.pricetype;
    if (pricetype == 0) {
      for (var i = 0; i < that.data.avgList.length; i++) {
        that.data.avgList[i].selectImage = false
      }
      that.setData({
        avgList: that.data.avgList,
      });
      for (var i = 0; i < that.data.totalList.length; i++) {
        if (idx == i) {
          that.data.totalList[i].selectImage = true
        } else {
          that.data.totalList[i].selectImage = false
        }
      }
      that.setData({
        totalList: that.data.totalList,
      });
    } else {
      for (var i = 0; i < that.data.totalList.length; i++) {
        that.data.totalList[i].selectImage = false
      }
      that.setData({
        totalList: that.data.totalList,
      });
      for (var i = 0; i < that.data.avgList.length; i++) {
        that.data.totalList[i].selectImage = false
        if (idx == i) {
          that.data.avgList[i].selectImage = true
        } else {
          that.data.avgList[i].selectImage = false
        }
      }
      that.setData({
        avgList: that.data.avgList,
      });
    }
  },
  // 确定价格筛选
  priceSure: function() {
    var that = this;
    setTimeout(function() {
      that.isShow();
    }, 800)
  },
  houseLimt: function(e) {
    var house = e.currentTarget.dataset.index;
    var that = this;
    for (let i in that.data.typeList) {
      var item = that.data.typeList[i];
      item.isSelected = false;
      that.setData({
        house: house,
        typeList: that.data.typeList,
      });
    }
  },
  clickHouse: function(e) {
    var index = e.currentTarget.dataset.index - 1;
    var that = this;
    var item = that.data.typeList[index];
    item.isSelected = !item.isSelected;
    that.setData({
      house: 999,
      typeList: that.data.typeList,
    });
  },
  houseSure: function() {
    var that = this;
    setTimeout(function() {
      that.isShow();
    }, 800)
  },
  // 筛选更多
  clickMore: function(e) {
    var id = e.currentTarget.dataset.id;
    var idx = e.currentTarget.dataset.index;
    var moreList = this.data.moreList;
    var that = this;
    for (var i = 0; i < moreList.length; i++) {
      if (id == i) {
        for (var j = 0; j < moreList[i].property.length; j++) {
          if (idx == j) {
            moreList[i].property[j].selectImage = true
          } else {
            moreList[i].property[j].selectImage = false
          }
        }
      }
    }
    that.setData({
      moreList: that.data.moreList,
    });
  },
  moreReset: function() {
    var moreList = this.data.moreList;
    for (var i = 0; i < moreList.length; i++) {
      for (var j = 0; j < moreList[i].property.length; j++) {
        moreList[i].property[j].selectImage = false
      }
    }
    this.setData({
      moreList: this.data.moreList,
    });
  },
  moreSure: function() {
    var that = this;
    setTimeout(function() {
      that.isShow();
    }, 800)
  },
  // 跳转到搜索页
  toSearch:function(){
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },
  // 跳转到联系客服页面
  toContact:function(){
    wx.redirectTo({
      url: '/pages/contact/contact',
    })
  },
  // 跳转到选择区域页面
  toArea:function(){
    wx.navigateTo({
      url: '/pages/area/area',
    });
  },
  // 跳转到详情页
  toSameDatail:function(){
    wx.navigateTo({
      url: '/pages/sameDetail/sameDetail',
    })
  },
  // 关闭认证弹出框
  closeIden:function(){
    this.setData({ showIden: false})
  },
  // 关闭VIP过期弹出框
  closeVIP:function(){
    this.setData({ showVIP: false })
  },
  // 关闭老用户初次登陆弹出框
  closeUser: function () {
    this.setData({ showUser: false })
  },
})